package ru.avn.devtool4j.tests.beans;

import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Date;
import java.util.ServiceLoader;

import org.junit.Test;

import ru.avn.devtool4j.spi.AnnotationProcessingService;
import ru.avn.devtool4j.spi.types.ClassType;
import ru.avn.devtool4j.spi.writers.impl.ClassWritterImpl;
import ru.avn.devtool4j.spi.writers.impl.FieldWritterImpl;

public class SimpleUnitTest {
	
	@Test
	public void loadServices() throws Exception {
		ServiceLoader<AnnotationProcessingService> serviceLoader = ServiceLoader.load(AnnotationProcessingService.class);
		
		for (AnnotationProcessingService serviceClass : serviceLoader) {
			System.out.println(Arrays.asList(serviceClass.supportedAnnotations()));
		}
		
	}
	
	
	@Test
	public void fieldBuild() throws Exception {
		FieldWritterImpl impl = new FieldWritterImpl();
		impl.addModifier(Modifier.PRIVATE)
			.addModifier(Modifier.STATIC)
			.setName("surname")
			.setType(Long.class)
			.setDefault(1L);
		
		System.out.println(impl.buildFieldCode());
	}
	
	
	@Test
	public void ClassBuild() throws Exception {
	
		ClassWritterImpl classWritterImpl = new ClassWritterImpl();
		classWritterImpl.setPackage("ru.avn.test");
		classWritterImpl.createClassBody("TestBean", ClassType.CLASS, new int[] {Modifier.ABSTRACT, Modifier.PUBLIC});
		
		classWritterImpl.addNewField()
			.addModifier(Modifier.PRIVATE)
			.addModifier(Modifier.STATIC)
			.setName("surname")
			.setType(Long.class)
			.setDefault(1L);
		
		classWritterImpl.addNewField()
		.addModifier(Modifier.PRIVATE)
		.addModifier(Modifier.STATIC)
		.setName("age")
		.setType(Integer.class)
		.setDefault(1);
		
		classWritterImpl.addNewField()
		.addModifier(Modifier.PRIVATE)
		.addModifier(Modifier.STATIC)
		.setName("age")
		.setType(Date.class);
				
		System.out.println(classWritterImpl.buildClassCode());
	}
	
}
